﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Collections.ObjectModel;
namespace PatientList
{

    public partial class PatientList : UserControl
    {

        // Declare the delegate (if using non-generic pattern).
        public delegate void SampleEventHandlerActive(object sender, int iNo);
        public delegate void SampleEventHandlerDeActive(object sender);
        // Declare the event.
        public event SampleEventHandlerActive SampleEventActive;
        public event SampleEventHandlerDeActive SampleEventDeActive;


        public ArrayList myList = new ArrayList();
        //Collection<PatientData> myList = new Collection<PatientData>();

        Bitmap bList = null;        // Gesamte gezeichnete Liste
        Bitmap bListShow = null;     // Nur der sichtbare Teil der Liste
        Bitmap bListBorder = null;  // Border der Liste

        bool bMouseOverList = false;
        int iHover = -1;
        int iDown = -1;
        int iItemHeight = 73;


        public PatientList()
        {
            InitializeComponent();

            // Init
            DrawBorder();
        }


        private void PatientList_Resize(object sender, EventArgs e)
        {
            // Liste & Border neu zeichnen
            DrawList(-1);
            DrawBorder();
        }

        private void ResizeScrollbar()
        {
            if (14 + (myList.Count * iItemHeight) > picUC.Height)
            {
                vScrollBar1.Minimum = 0;
                vScrollBar1.Maximum = (14 + (myList.Count * iItemHeight)) - picUC.Height;
                vScrollBar1.LargeChange = iItemHeight;
                vScrollBar1.Visible = true;
            }
            else
            {
                vScrollBar1.Visible = false;
                vScrollBar1.Value = 0;
            }
        }


        public void RedrawShowArea()
        {
            if ((myList.Count == 0) || (bList == null) || ((picUC.Width==0)&&(picUC.Height==0))) return;
            bListShow = new Bitmap(picUC.Width, picUC.Height);
            bListShow.SetResolution(96, 96);

            Graphics g = Graphics.FromImage(bListShow);
            g.DrawImage(bList, 0, -vScrollBar1.Value);

            picUC.BackgroundImage = bListShow;
            DrawBorder();


            
            picUC.Refresh();
            
            picUC.Invalidate();
            

        }

        public void MakeDark(bool yes=true)
        {
            if (yes == true)
            {
                bMouseOverList = false;
                picUC.Enabled = false;
                vScrollBar1.Enabled = false;
                this.Enabled = false;

                Rectangle srcRect_D2Dark = new Rectangle((1 + 4 * 43 + 22) + 13, 33 + 3 + 3, 2, 2);
                Rectangle srcRect_D2Dark_Dest = new Rectangle(0, 0, picUC.Image.Width, picUC.Image.Height);
                Graphics g = Graphics.FromImage(picUC.Image);

                g.DrawImage(picPattern.Image, srcRect_D2Dark_Dest, srcRect_D2Dark, GraphicsUnit.Pixel);
            }
            else
            {
                picUC.Enabled = true;
                vScrollBar1.Enabled = true;
                this.Enabled = true;
                bListBorder = null;
                DrawBorder();
            }
            picUC.Invalidate();
        }

        public void RedrawAll()
        {
            DrawList(-1);
            DrawBorder();
        }

        // Funktion Zeichnet Liste
        //   iDrawItem == -1    , gesamte Liste
        //   iDrawItem =>  0    , einzelnes Item
        private void DrawList(int iDrawItem = -1)
        {

            // Wenn Liste leer, abbrechen
            if (myList.Count == 0)
            {
                picUC.BackgroundImage = null;
                return;
            }


            // Prüfe ob altes Bild noch verwendbar
            if (((bList == null) || (bList.Width != picUC.Width) || (bList.Height != (14 + iItemHeight * myList.Count))) && !(picUC.Width==0))
            {
                // Leider Nein. => Neues anlegen
                bList = new Bitmap(picUC.Width, myList.Count * iItemHeight + 14);
                bList.SetResolution(96, 96);
            }

            if (iDrawItem == -1)
            {
                // Alle Items aus Liste zeichnen
                for (int i = 0; i < myList.Count; i++)
                {
                    DrawItem(i, bList);
                }
                ResizeScrollbar();
            }
            else
                if ((iDrawItem >= 0) && (iDrawItem < myList.Count))
                {
                    DrawItem(iDrawItem, bList);
                }

            RedrawShowArea();

        }

        void DrawItem(int iNo, Bitmap b)
        {
            // Pattern Item
            Rectangle srcRect_D2Green = new Rectangle((1 + 0 * 43), 1, 43, 72);
            Rectangle srcRect_D2Yellow = new Rectangle((1 + 1 * 43), 1, 43, 72);
            Rectangle srcRect_D2Orange = new Rectangle((1 + 2 * 43), 1, 43, 72);
            Rectangle srcRect_D2Red = new Rectangle((1 + 3 * 43), 1, 43, 72);

            Rectangle srcRect_D2FillGreen = new Rectangle((1 + 4 * 43 + 1), 3, 1, 52);
            Rectangle srcRect_D2FillYellow = new Rectangle((1 + 4 * 43 + 4), 3, 1, 52);
            Rectangle srcRect_D2FillOrange = new Rectangle((1 + 4 * 43 + 7), 3, 1, 52);
            Rectangle srcRect_D2FillRed = new Rectangle((1 + 4 * 43 + 10), 3, 1, 52);

            Rectangle srcRect_D2CLT = new Rectangle((1 + 4 * 43 + 22), 3, 10, 10);
            Rectangle srcRect_D2CT = new Rectangle((1 + 4 * 43 + 22 + 11), 3, 9, 10);
            Rectangle srcRect_D2CL = new Rectangle((1 + 4 * 43 + 22), 3 + 11, 10, 9);
            Rectangle srcRect_D2CLB = new Rectangle((1 + 4 * 43 + 22), 3 + 11 + 11, 10, 9);
            Rectangle srcRect_D2CB = new Rectangle((1 + 4 * 43 + 22 + 11), 3 + 11 + 11, 9, 10);

            Rectangle srcRect_D2CLT_Hover = new Rectangle((1 + 4 * 43 + 22), 33 + 3, 10, 10);
            Rectangle srcRect_D2CT_Hover = new Rectangle((1 + 4 * 43 + 22 + 11), 33 + 3, 9, 10);
            Rectangle srcRect_D2CL_Hover = new Rectangle((1 + 4 * 43 + 22), 33 + 3 + 11, 10, 9);
            Rectangle srcRect_D2CLB_Hover = new Rectangle((1 + 4 * 43 + 22), 33 + 3 + 11 + 11, 10, 9);
            Rectangle srcRect_D2CB_Hover = new Rectangle((1 + 4 * 43 + 22 + 11), 33 + 3 + 11 + 11, 9, 10);

            Rectangle srcRect_D2CLT_Down = new Rectangle((1 + 4 * 43 + 22 + 22), 33 + 3, 10, 10);
            Rectangle srcRect_D2CT_Down = new Rectangle((1 + 4 * 43 + 22 + 22 + 11), 33 + 3, 9, 10);
            Rectangle srcRect_D2CL_Down = new Rectangle((1 + 4 * 43 + 22 + 22), 33 + 3 + 11, 10, 9);
            Rectangle srcRect_D2CLB_Down = new Rectangle((1 + 4 * 43 + 22 + 22), 33 + 3 + 11 + 11, 10, 9);
            Rectangle srcRect_D2CB_Down = new Rectangle((1 + 4 * 43 + 22 + 22 + 11), 33 + 3 + 11 + 11, 9, 10);

            Graphics g = Graphics.FromImage(b);

            // Read the item
            PLItem myData = (PLItem)myList[iNo];

            // Alten Bereich löschen
            g.FillRectangle(new SolidBrush(picUC.BackColor), 0, 8 + (iItemHeight * iNo), b.Width, iItemHeight);
            if (iNo == 0) g.FillRectangle(new SolidBrush(picUC.BackColor), 0, 0, b.Width, 8);
            if (iNo == myList.Count-1) g.FillRectangle(new SolidBrush(picUC.BackColor), 0, b.Height-8, b.Width, 8);

            // Lines Rects
            Rectangle srcRect_D2FillLineTop = new Rectangle(18, iNo * iItemHeight + 8, b.Width - (18 + 61), 10);
            Rectangle srcRect_D2FillLineLeft = new Rectangle(8, iNo * iItemHeight + 8 + 10, 10, 52);
            Rectangle srcRect_D2FillLineBottom = new Rectangle(18, iNo * iItemHeight + 8 + 10 + 52, b.Width - (18 + 61), 10);

            // Ränder je nach Status printen
             if (iNo == iHover) {
                
                    // Corners
                    g.DrawImage(picPattern.Image, 8, iNo * iItemHeight + 8, srcRect_D2CLT_Hover, GraphicsUnit.Pixel);
                    g.DrawImage(picPattern.Image, 8, iNo * iItemHeight + 8 + 10 + 52, srcRect_D2CLB_Hover, GraphicsUnit.Pixel);

                    // Lines
                    g.DrawImage(picPattern.Image, srcRect_D2FillLineTop, srcRect_D2CT_Hover, GraphicsUnit.Pixel);
                    g.DrawImage(picPattern.Image, srcRect_D2FillLineLeft, srcRect_D2CL_Hover, GraphicsUnit.Pixel);
                    g.DrawImage(picPattern.Image, srcRect_D2FillLineBottom, srcRect_D2CB_Hover, GraphicsUnit.Pixel);
            } else if (iNo == iDown) {
                    // Corners
                    g.DrawImage(picPattern.Image, 8, iNo * iItemHeight + 8, srcRect_D2CLT_Down, GraphicsUnit.Pixel);
                    g.DrawImage(picPattern.Image, 8, iNo * iItemHeight + 8 + 10 + 52, srcRect_D2CLB_Down, GraphicsUnit.Pixel);

                    // Lines
                    g.DrawImage(picPattern.Image, srcRect_D2FillLineTop, srcRect_D2CT_Down, GraphicsUnit.Pixel);
                    g.DrawImage(picPattern.Image, srcRect_D2FillLineLeft, srcRect_D2CL_Down, GraphicsUnit.Pixel);
                    g.DrawImage(picPattern.Image, srcRect_D2FillLineBottom, srcRect_D2CB_Down, GraphicsUnit.Pixel);
              
              }else{ 

                    // Corners
                    g.DrawImage(picPattern.Image, 8, iNo * iItemHeight + 8, srcRect_D2CLT, GraphicsUnit.Pixel);
                    g.DrawImage(picPattern.Image, 8, iNo * iItemHeight + 8 + 10 + 52, srcRect_D2CLB, GraphicsUnit.Pixel);

                    // Lines
                    g.DrawImage(picPattern.Image, srcRect_D2FillLineTop, srcRect_D2CT, GraphicsUnit.Pixel);
                    g.DrawImage(picPattern.Image, srcRect_D2FillLineLeft, srcRect_D2CL, GraphicsUnit.Pixel);
                    g.DrawImage(picPattern.Image, srcRect_D2FillLineBottom, srcRect_D2CB, GraphicsUnit.Pixel);


            }

            // Fill
            Rectangle srcRect_D2FillLineGreen = new Rectangle(18, iNo * iItemHeight + 8 + 10, b.Width - (18 + 61), 52);
            if (myData.Data.getStatus() == 1) g.DrawImage(picPattern.Image, srcRect_D2FillLineGreen, srcRect_D2FillGreen, GraphicsUnit.Pixel);
            else if (myData.Data.getStatus() == 2) g.DrawImage(picPattern.Image, srcRect_D2FillLineGreen, srcRect_D2FillYellow, GraphicsUnit.Pixel);
            else if (myData.Data.getStatus() == 3) g.DrawImage(picPattern.Image, srcRect_D2FillLineGreen, srcRect_D2FillOrange, GraphicsUnit.Pixel);
            else g.DrawImage(picPattern.Image, srcRect_D2FillLineGreen, srcRect_D2FillRed, GraphicsUnit.Pixel);
            
            // End Status
            if (myData.Data.getStatus() == 1) g.DrawImage(picPattern.Image, b.Width - 61, iNo * iItemHeight + 7, srcRect_D2Green, GraphicsUnit.Pixel);
            else if (myData.Data.getStatus() == 2) g.DrawImage(picPattern.Image, b.Width - 61, iNo * iItemHeight + 7, srcRect_D2Yellow, GraphicsUnit.Pixel);
            else if (myData.Data.getStatus() == 3) g.DrawImage(picPattern.Image, b.Width - 61, iNo * iItemHeight + 7, srcRect_D2Orange, GraphicsUnit.Pixel);
            else g.DrawImage(picPattern.Image, b.Width - 61, iNo * iItemHeight + 7, srcRect_D2Red, GraphicsUnit.Pixel);

            DrawText(g, myData ,iNo);
            
            //Console.WriteLine(DateTime.Now.ToString("mm:ss:ff").ToString() + ": PatientList: Draw item:" + iNo.ToString());
        }

        // Zeichnet Border von Liste neu !
        void DrawBorder()
        {
            // Existiert noch kein Bild ODER stimmen die Maße mit dem alten Bild nicht überein ?
            if (((bListBorder == null) || (bListBorder.Height != picUC.Height) || (bListBorder.Width != picUC.Width)) && !((picUC.Width==0)&&(picUC.Height==0)))
            {
                // => Nein ! - Bitmap neu anlegen
                bListBorder = new Bitmap(picUC.Width, picUC.Height);
                bListBorder.SetResolution(96, 96);

                Graphics g = Graphics.FromImage(bListBorder);

                // Pattern Border
                Rectangle srcRect_D2BorderTL = new Rectangle(219, 3, 7, 7);
                Rectangle srcRect_D2BorderL = new Rectangle(219, 12, 7, 1);
                Rectangle srcRect_D2BorderBL = new Rectangle(219, 16, 7, 7);
                Rectangle srcRect_D2BorderB = new Rectangle(219 + 9, 16, 1, 7);
                Rectangle srcRect_D2BorderBR = new Rectangle(219 + 9 + 4, 16, 7, 7);
                Rectangle srcRect_D2BorderR = new Rectangle(219 + 9 + 4, 12, 7, 1);
                Rectangle srcRect_D2BorderTR = new Rectangle(219 + 9 + 4, 3, 7, 7);
                Rectangle srcRect_D2BorderT = new Rectangle(219 + 9, 3, 1, 7);

                // Border zeichnen
                g.DrawImage(picPattern.Image, 0, 0, srcRect_D2BorderTL, GraphicsUnit.Pixel);
                g.DrawImage(picPattern.Image, bListBorder.Width - 7, 0, srcRect_D2BorderTR, GraphicsUnit.Pixel);
                g.DrawImage(picPattern.Image, 0, this.Height - 7, srcRect_D2BorderBL, GraphicsUnit.Pixel);
                g.DrawImage(picPattern.Image, bListBorder.Width - 7, this.Height - 7, srcRect_D2BorderBR, GraphicsUnit.Pixel);
                Rectangle srcRect_D2BorderFillT = new Rectangle(7, 0, bListBorder.Width - 14, 7);
                Rectangle srcRect_D2BorderFillL = new Rectangle(0, 7, 7, this.Height - 14);
                Rectangle srcRect_D2BorderFillB = new Rectangle(7, this.Height - 7, bListBorder.Width - 14, 7);
                Rectangle srcRect_D2BorderFillR = new Rectangle(bListBorder.Width - 7, 7, 7, bListBorder.Height - 14);
                g.DrawImage(picPattern.Image, srcRect_D2BorderFillT, srcRect_D2BorderT, GraphicsUnit.Pixel);
                g.DrawImage(picPattern.Image, srcRect_D2BorderFillL, srcRect_D2BorderL, GraphicsUnit.Pixel);
                g.DrawImage(picPattern.Image, srcRect_D2BorderFillB, srcRect_D2BorderB, GraphicsUnit.Pixel);
                g.DrawImage(picPattern.Image, srcRect_D2BorderFillR, srcRect_D2BorderR, GraphicsUnit.Pixel);

                picUC.Image = bListBorder;
                //picUC.Size = bListBorder.Size;
                //Console.WriteLine(DateTime.Now.ToString("mm:ss:ff").ToString() + ": PatientList: Redrawed border");
            }
        }

        void DrawText(Graphics g, PLItem myData,int  iNo)
        {
            // Patient Informationen (Name, Messwerte)
            Font textFont = new Font("Kalinga", 10);
            Font textFontNameFett = new Font("Kalinga", 12,FontStyle.Bold );
            Font textFontA = new Font("Kalinga", 16);
            Font textFontB = new Font("Kalinga", 8);

            // gesamt width 516pxl
            int iNameWidth = 120;
            int iTemperaturWidth = Convert.ToInt32((picUC.Width - 208) * 0.2);
            int iBlutdruckWidth = Convert.ToInt32((picUC.Width - 208) * 0.2144);
            int iPulsWidth = Convert.ToInt32((picUC.Width - 208) * 0.1712);
            int iSauerstoffsaettigungWidth = Convert.ToInt32((picUC.Width - 208) * 0.2);
            int iAtemfrequenzWidth = Convert.ToInt32((picUC.Width - 208) * 0.2144);
            

            // Position Left: Temperatur
            int iTemperaturLeft = iNameWidth + (iTemperaturWidth - Convert.ToInt32(g.MeasureString(myData.Data.aktuelleDaten.Temperatur.ToString(), textFontA).Width)) / 2;
            int iTemperaturLeftLabel = iTemperaturLeft + Convert.ToInt32(g.MeasureString(myData.Data.aktuelleDaten.Temperatur.ToString(), textFontA).Width);

            // Position Left: Sauerstoffsättigung ->Blutdruck
            int iBlutdruckLeft = iNameWidth + iTemperaturWidth+ (iBlutdruckWidth - Convert.ToInt32(g.MeasureString(myData.Data.aktuelleDaten.Blutdruck.ToString(), textFontA).Width)) / 2;
            int iBlutdruckLeftLabel = iBlutdruckLeft + Convert.ToInt32(g.MeasureString(myData.Data.aktuelleDaten.Blutdruck.ToString(), textFontA).Width);
            
            // Position Left: Puls
            int iPulsLeft = iNameWidth + iTemperaturWidth+ iBlutdruckWidth +(iPulsWidth - Convert.ToInt32(g.MeasureString(myData.Data.aktuelleDaten.Puls.ToString(), textFontA).Width)) / 2;
            int iPulsLeftLabel = iPulsLeft + Convert.ToInt32(g.MeasureString(myData.Data.aktuelleDaten.Puls.ToString(), textFontA).Width);
            
            // Position Left: Atemfrequenz -> Sauerstoffsättigung
            int iSauerstoffsaettigungLeft = iNameWidth + iTemperaturWidth + iBlutdruckWidth + iPulsWidth + (iSauerstoffsaettigungWidth - Convert.ToInt32(g.MeasureString(myData.Data.aktuelleDaten.Sauerstoffsaettigung.ToString(), textFontA).Width)) / 2;
            int iSauerstoffsaettigungLeftLabel = iSauerstoffsaettigungLeft + Convert.ToInt32(g.MeasureString(myData.Data.aktuelleDaten.Sauerstoffsaettigung.ToString(), textFontA).Width);
            
            // Position Left: Blutdruck -> Atemfrequenz
            int iAtemfrequenzLeft = iNameWidth + iTemperaturWidth + iBlutdruckWidth + iPulsWidth  + iSauerstoffsaettigungWidth+ (iAtemfrequenzWidth - Convert.ToInt32(g.MeasureString(myData.Data.aktuelleDaten.Atemfrequenz.ToString(), textFontA).Width)) / 2;
            int iAtemfrequenzLeftLabel = iAtemfrequenzLeft + Convert.ToInt32(g.MeasureString(myData.Data.aktuelleDaten.Atemfrequenz.ToString(), textFontA).Width);
            

            
            // Name Vorname
            g.DrawString(myData.Data.name, textFontNameFett, Brushes.Black, 30, iNo * iItemHeight + 25);
            g.DrawString(myData.Data.vorname, textFont, Brushes.Black, 32, iNo * iItemHeight + 45);

            // Messwerte zentriert ausgeben
            g.DrawString(myData.Data.aktuelleDaten.Temperatur.ToString(), textFontA, Brushes.Black, iTemperaturLeft, iNo * iItemHeight + 30);
            g.DrawString(myData.Data.aktuelleDaten.Blutdruck.ToString(), textFontA, Brushes.Black, iBlutdruckLeft, iNo * iItemHeight + 30);
            g.DrawString(myData.Data.aktuelleDaten.Puls.ToString(), textFontA, Brushes.Black, iPulsLeft, iNo * iItemHeight + 30);
            g.DrawString(myData.Data.aktuelleDaten.Sauerstoffsaettigung.ToString(), textFontA, Brushes.Black, iSauerstoffsaettigungLeft, iNo * iItemHeight + 30);
            g.DrawString(myData.Data.aktuelleDaten.Atemfrequenz.ToString(), textFontA, Brushes.Black, iAtemfrequenzLeft, iNo * iItemHeight + 30);

            // °c mmHg bpm %  rpm
            g.DrawString("°C", textFont, Brushes.Gray,iTemperaturLeftLabel, iNo * iItemHeight + 37);
            g.DrawString("%", textFont, Brushes.Gray, iSauerstoffsaettigungLeftLabel, iNo * iItemHeight + 37);
            g.DrawString("bpm", textFont, Brushes.Gray, iPulsLeftLabel, iNo * iItemHeight + 37);
            g.DrawString("rpm", textFont, Brushes.Gray, iAtemfrequenzLeftLabel, iNo * iItemHeight + 37);
            g.DrawString("mmHg", textFont, Brushes.Gray, iBlutdruckLeftLabel, iNo * iItemHeight + 37);

            

        }

        private void picUC_MouseMove(object sender, MouseEventArgs e)
        {
            int iItemHover = CalculateIndexPos(e.X, e.Y);

            if (iItemHover == -1)
            {
                // Außerhalb !
                // Rücksetzen alten Hover
                int iLastHover = iHover;
                iHover = -1;
                DrawList(iLastHover);
                picUC.Invalidate();
            }
            else
            {
                // Innerhalb !
                if ((iHover != iItemHover) && (iDown != iItemHover))
                {

                    // Rücksetzen alten Hover
                    int iLastHover = iHover;
                    iHover = -1;
                    DrawList(iLastHover);
                    // Setze neuen Hover
                    iHover = iItemHover;
                    DrawList(iItemHover);

                    picUC.Invalidate();
                }
            }
        }

        private void picUC_MouseDown(object sender, MouseEventArgs e)
        {
            int iItemDown = CalculateIndexPos(e.X, e.Y);

            if (iItemDown == -1)
            {
                // Außerhalb !
                int iLastDown = iDown;
                iDown = -1;
                DrawList(iLastDown);
                picUC.Invalidate();
                SampleEventDeActive(this);
            }
            else
            {
                // Innerhalb !
                if ((iDown != iItemDown))
                {
                    int iLastDown = iDown;
                    iDown = -1;
                    DrawList(iLastDown);

                    iDown = iItemDown;
                    DrawList(iItemDown);
                    picUC.Invalidate();
                    // Raise the event by using the () operator.
                    SampleEventActive(this, iItemDown);
        
                }
            }
        }

        // Berechnet  anhand Koordinaten den Index des Items
        int CalculateIndexPos(int x, int y)
        {
            // Offset durch Scrollbar berueksichtigen!
            int oY = y + vScrollBar1.Value;

            // Index des Items berechnen!
            int iItemPos = ((oY - 8) / iItemHeight);


            // Index innerhalb des List Bereichs?
            if (iItemPos >= 0 && iItemPos < myList.Count)
            {
                // Genaue Position auf Item berechnen!
                int iY = (oY - 8) - (iItemPos * iItemHeight);

                // Item Rahmen ausschließen!
                if ((x <= 12 || x >= (picUC.Width - 23)) || ((iY <= 4) || (iY >= iItemHeight - 4)))
                {
                    // Ausserhalb !
                    return -1;
                }
                else
                {
                    //Innerhalb
                    return iItemPos;
                }
            }
            return -1;

        }


        private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            RedrawShowArea();
        }

        private void picUC_MouseLeave(object sender, EventArgs e)
        {
            int iLastHover = iHover;
            iLastHover = -1;
            DrawList(iLastHover);
            bMouseOverList = false;
        }



        private void pbFinalHud_MouseWheel(object sender, MouseEventArgs e)
        {

            if ((bMouseOverList==true) && (vScrollBar1.Visible==true))
            {
                if (e.Delta < 0)
                {
                    if (vScrollBar1.Value > (vScrollBar1.Maximum - iItemHeight))
                    {
                        vScrollBar1.Value = vScrollBar1.Maximum;
                        RedrawShowArea();
                    }
                    else if (vScrollBar1.Value <= (vScrollBar1.Maximum-iItemHeight))
                    {
                        vScrollBar1.Value = vScrollBar1.Value + vScrollBar1.LargeChange;
                        RedrawShowArea();
                    }

                }
                else
                {
                  if (vScrollBar1.Value < iItemHeight) {
                      vScrollBar1.Value=0;
                      RedrawShowArea();
                  }else if (vScrollBar1.Value >= iItemHeight){
                    vScrollBar1.Value = vScrollBar1.Value - vScrollBar1.LargeChange;
                    RedrawShowArea();
                }
                }
            }

        }



        private void picUC_MouseEnter(object sender, EventArgs e)
        {
            bMouseOverList = true;
            picUC.Focus();
        }

        public int getSelected()
        {
            return iDown;
        }
        public int getHovered()
        {
            return iHover;
        }


    }
}
